<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<link
	href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css"
	rel="stylesheet" />
<link href="${basePath}/js/fileInput/css/fileinput.css" media="all"
	rel="stylesheet" type="text/css" />
<!doctype html>
<html>
<head>
<style type="text/css">
	.ibox-content {
		border: none;
	}
	.progress {
   	 	margin-top: 15px!important;
   	 	margin-bottom:0px;
	}
	
	.ibox-zxsearchqu {
	    padding-bottom: 5px!important;
	}
</style>
</head>
<body class="gray-bg">
	<div class="container creditbody">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;贷中业务>银行信息>导入银行客户</span>
		</div>
		<div class="ibox-content  ibox-zxsearchqu">
			<div class="uploadfile-btn">
				<form enctype="multipart/form-data">
					<input type="hidden" id="uploadName" /> <input id="uploadfile"
						name="uploadfile" type="file" multiple data-min-file-count="1" />
				</form>
			</div>
			<div class="uploadfile-btnb td-width">
				<select class="select-control" id="bankCode" name="bankCode">
				</select>
			</div>
			<div class="uploadfile-btnc">
				<button class="btn dpbtn_grey_heigth" type="button" onclick="preview();">导入预览</button>
				<button class="btn dpbtn_grey_heigth" type="button" onclick="importDueList();">确认导入</button>
			</div>
		</div>


		<div class="ibox-content">
			<div class="jqGrid_wrapper">
				<table id="table_list_1"></table>
				<div id="pager_list_1"></div>
			</div>
		</div>
	</div>

	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>

	<!-- jqGrid -->
	<script type="text/javascript" charset="utf-8"
		src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" charset="utf-8"
		src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>
	<script src="${basePath}/js/fileInput/js/fileinput.js"
		type="text/javascript"></script>
	<script src="${basePath}/js/fileInput/js/locales/zh.js"
		type="text/javascript"></script>

	<script type="text/javascript">
		var winWidth = $(window).width();
		var winHeight = $(window).height();
		 jQuery(function($) { 
	    	initTable();
	    	initBankDic();
	    });
		 var initBankDic=function(){
		    	$.dpAjax({
			    	url:'${basePath}/DataDictionaryController/getEnableList',
			    	
		 			data:{
		 				"parentValue":"LoanBank"
		 			},
		 			success: function(datas){
		 				  if(datas.flag == "100100")
							  {
			 					  var result = datas.result.rows;
			 					  var programme_sel=[];
			 				      for(var i=0;i<result.length;i++){
			 				          var programme = result[i];
			 				          programme_sel.push('<option value="'+programme.value+'">'+programme.name+'</option>')
			 				      }
			 				     $("#bankCode").html(programme_sel.join(' '));
								  return;
							  }
							  if(datas.flag == "100200")
			                  {
								  $.fn.showDatas({"datas":datas});
			                	  return;
			                  }
							  layer.msg(datas.message, {icon: 2});
		              }
			    	});
		    }
	    var importDueList=function(){
		   var uploadName=$("#uploadName").val();
		   var bankCode=$('#bankCode option:selected').val();
		   $.dpAjax({
	    		url:'${basePath}/DzLoanMiddleBankController/importBankInfo',
	    		data:{"uploadName":uploadName,"bankCode":bankCode},
   				success: function(datas){
	    			  if(datas.flag == "100100")
					  {
						  layer.msg('执行成功！', {icon: 6});
						  return;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
	                	  return;
	                  }
					  if(datas.flag == "100300")
	                  {
						  layer.msg('请选择正确的excel导入！', {icon: 8});
	                	  return;
	                  }
					  if(datas.flag == "101802")
	                  {
						  layer.msg('请选择正确的银行导入！', {icon: 8});
	                	  return;
	                  }
                }
	    	});
	   }
	 	var initTable=function(){
	 		 var winWidth = $('div.ibox-content').width();
	  	 	var winHeight = $(window).height() -450;
		 	var win = winWidth / 7 - 20;
	 	 	$.jgrid.defaults.styleUI = 'Bootstrap';
	 	 	var initFlag=true;
		 	$("#table_list_1").jqGrid({
		 		url:'${basePath}/DzLoanMiddleBankController/previewDueList',
		     	datatype : "json",
		       	postData:{"uploadName":$("#uploadName").val(),"initFlag":initFlag},
			    colNames : ['客户姓名','身份证号', '放贷金额','放款时间', '放款状态','先抵押 ', '卡号 ', '合同号'],
			    colModel : [ 
		             {name: 'creatorName',index: 'creatorName',width: 130,align: "center",sorttype: "float"},
		             {name: 'cusNo',index: 'cusNo',width: 170,align: "center",sorttype: "float"},
		             {name: 'loanAmount',index: 'loanAmount',width: 130,align: "center",sorttype: "float"},
		             {name: 'loanDate',index: 'loanDate',width: 170,align: "center",sorttype: "float"},
		             {name: 'loanStatus',index: 'loanStatus',width: 170,align: "center",sorttype: "float"},
		             {name: 'txtPledge',index: 'txtPledge',width: 170,align: "center",sorttype: "float"},
		             {name: 'cardnoRefund',index: 'cardnoRefund',width: 170,align: "center",sorttype: "float"},
		             {name: 'contractNo',index: 'contractNo',width: 170,align: "center",sorttype: "float"}
		             ],
		           mtype : "post",
		           height: winHeight+200,
		           width:winWidth,  
		           autowidth: false,
		           shrinkToFit: false,
		           rowNum: 50,
//	 	           rowList: [10, 20, 30,40,50],
		           viewrecords: true,
		           pager: "#pager_list_1",
		           hidegrid: false,
		           multiselect : false,		//实现单选    multiboxonly:true   beforeSelectRow: true,
		           multiboxonly:false,  
		           beforeSelectRow: false,
		           altRows:true,
		           altclass:'someClass',
		           loadComplete: function(datas){
		        	   if(datas.flag==100100){
		        		   if(initFlag==false){
			        		   layer.msg('预览成功！', {icon: 6});
		        		   }
			        		   return;
		        	   }
		        	   if(datas.flag == "100300")
		                  {
							  layer.msg('请选择正确的excel导入！', {icon: 8});
		                	  return;
		                  }
		        	   $.fn.showDatas({"datas":datas});
		        	   return ;
		           },
		           jsonReader: {
		                root: "result.rows",
		                page: "result.page",
		                total: "result.total",
		                records: "result.records",
		                repeatitems: false,
		                id: "replaceId"
		            },
		            loadComplete:function(datas){
		          	  if (datas.flag == "100100") {
		                    layer.msg("查询成功!", {icon: 6, time: 1000});
		                    return;
		                }
		          	  if(datas.flag == '100802') {
		  				  top.location.href = thisLoginUrl;
		  				  return;
		  			  }

		          	  layer.msg(datas.message, {icon: 2});
		            }
		      });
	 }
	var preview = function(){
		var postData = $("#table_list_1").jqGrid("getGridParam", "postData");
    	var data = {};
    	var uploadfile = $("#uploadName").val();
  	    if(uploadfile==""){
  	    	layer.msg('请先上传表格，再预览！', {icon: 5});
  	    	return false;
  	    }
    	data.uploadName =$("#uploadName").val() || '';
    	data.initFlag=false;
    	$.extend(postData, data);
		$("#table_list_1").jqGrid("setGridParam", { search: true }).trigger("reloadGrid", [{ page: 1}])
	    }
    window.onresize = function()
    {
    	 $("#table_list_1").setGridWidth($(window).width()-80);
    	 $("#table_list_1").setGridHeight($(window).height() / 2.5);
    }
    var carSeriesChoose=function(){
    	
    }
	var carSeriesUnChoose=function(){
    	
    }
	$("#uploadfile").fileinput({
   	 language: 'zh', //设置语言
   	 uploadUrl: "${basePath}/FileController/upload?flag=true", //上传的地址(访问接口地址)
   	 allowedFileExtensions: ['xlsx'],//接收的文件后缀
   	 showUpload: false, //是否显示上传按钮
   	 showRemove : false, //显示移除按钮
   	 showPreview : false, //是否显示预览
   	 dropZoneEnabled: false,//是否显示拖拽区域
   	 minImageWidth:'1',
  	}).on("filebatchselected", function(event, files) {
        $(this).fileinput("upload");
    })
    .on("fileuploaded", function(event, datas) {
    	jQuery("#table_list_1").jqGrid("clearGridData");
    	 if(datas.response.flag==100100){
	  			$("#uploadName").val(datas.response.result.name);
	  	}
	});
    </script>
</body>
</html>
